package com.woniu.adminservice.config;

import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * 监听访问人数，有一个人访问页面，就在session里存一个count+1
 */
@Component
public class VisitCountListener implements HttpSessionListener {
    public Integer count=0;
    public Integer online=0;
    //Session被创建时
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        count++;
        online++;
        se.getSession().getServletContext().setAttribute("count",count);
        se.getSession().getServletContext().setAttribute("online",online);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        online--;
        se.getSession().getServletContext().setAttribute("online",online);
    }
}
